<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Bandit-Blog后台</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/editor.md-master/css/editormd.css">
</head>
<body>

<div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">Bandit-Blog后台</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-left">
        <!-- 移动端显示 -->
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
            <i class="layui-icon layui-icon-spread-left"></i>
        </li>

        <li class="layui-nav-item"><a href="/toIndex">去前端</a></li>
        <li class="layui-nav-item layui-hide-xs"><a href="">没想好</a></li>
        <li class="layui-nav-item">
            <a href="javascript:;">也没想好</a>
            <dl class="layui-nav-child">
                <dd><a href="">menu 11</a></dd>
                <dd><a href="">menu 22</a></dd>
                <dd><a href="">menu 33</a></dd>
            </dl>
        </li>
    </ul>

</div>
<%--侧边栏--%>
<div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
        <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
        <ul class="layui-nav layui-nav-tree" lay-filter="test">
            <li class="layui-nav-item layui-nav-itemed">
                <a class="" href="javascript:;">首页管理</a>
                <dl class="layui-nav-child">
                    <dd><a href="/toBackIndex">去首页</a></dd>
                    <dd><a href="/toPasswordModify">密码修改</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item layui-nav-itemed">
                <a class="" href="javascript:;">博客管理</a>
                <dl class="layui-nav-child">
                    <dd><a href="/toBlogManger">博客列表</a></dd>
                    <dd><a href="/toBlogAdd">写一条博客</a></dd>
                    <dd><a href="/toTypeManger">标签列表</a></dd>
                    <dd><a href="/toCommentManger">评论管理</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="javascript:;">还没想好</a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;">list 1</a></dd>
                    <dd><a href="javascript:;">list 2</a></dd>
                    <dd><a href="">超链接</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="javascript:;">友链管理</a></li>
        </ul>
    </div>
</div>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/editor.md-master/editormd.js"></script>
<script type="text/html" id="toolbarBlog">
    <%--头部工具栏--%>
    <div class="layui-row">
        <div class="layui-col-lg2">
            <div class="layui-btn-container">
                <button class="layui-btn" lay-event="add" onclick="window.location.href='/toBlogAdd'">添加</button>
            </div>
        </div>
        <div class="layui-col-lg10">
            <div class="demoTable">
                搜索ID：
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="IDReload" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="toolbarType">
    <%--头部工具栏--%>
    <div class="layui-row">
        <div class="layui-col-lg2">
            <div class="layui-btn-container">
                <button class="layui-btn" lay-event="add" onclick="window.location.href='/toBlogAdd'">添加</button>
            </div>
        </div>
        <div class="layui-col-lg10">
            <div class="demoTable">
                搜索ID：
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="TypeIDReload" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="toolbarComment">
    <%--头部工具栏--%>
    <div class="layui-row">
        <div class="layui-col-lg12">
            <div class="demoTable">
                搜索ID：
                <div class="layui-inline">
                    <input class="layui-input" name="id" id="CommentIDReload" autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="barBlog">
    <%--侧边工具栏--%>
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="barType">
    <%--侧边工具栏--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="barComment">
    <%--侧边工具栏--%>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
<%--editormd图片上传脚本--%>
    function initPasteDragImg(Editor){
        var doc = document.getElementById(Editor.id)
        doc.addEventListener('paste', function (event) {
            var items = (event.clipboardData || window.clipboardData).items;
            var file = null;
            console.log(items)
            console.log(items.length)
            if (items && items.length) {
                // 搜索剪切板items
                for (var i = 0; i < items.length; i++) {
                    if (items[i].type.indexOf('image') !== -1) {
                        file = items[i].getAsFile();
                        break;
                    }
                }
            }
            else {
                console.log("当前浏览器不支持");
                return;
            }
            if (!file) {
                console.log("粘贴内容非图片");
                return;
            }
            uploadImg(file,Editor);
        });
        var dashboard = document.getElementById(Editor.id)
        dashboard.addEventListener("dragover", function (e) {
            e.preventDefault()
            e.stopPropagation()
        })
        dashboard.addEventListener("dragenter", function (e) {
            e.preventDefault()
            e.stopPropagation()
        })
        dashboard.addEventListener("drop", function (e) {
            e.preventDefault()
            e.stopPropagation()
            var files = this.files || e.dataTransfer.files;
            uploadImg(files[0],Editor);
        })
    }

    function uploadImg(file,Editor){
        var formData = new FormData();
        var fileName=new Date().getTime()+"."+file.name.split(".").pop();
        formData.append('editormd-image-file', file, fileName);
        $.ajax({
            url: Editor.settings.imageUploadURL,
            type: 'post',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success: function (msg) {
                var success=msg['success'];
                if(success==1){
                    var url=msg["url"];
                    if(/\.(png|jpg|jpeg|gif|bmp|ico)$/.test(url)){
                        Editor.insertValue("![]("+msg["url"]+")");
                    }else{
                        Editor.insertValue("[下载附件]("+msg["url"]+")");
                    }
                }else{
                    console.log(msg);
                    alert("上传失败");
                }
            }
        });
    }
</script>
</body>
</html>
